﻿using JmShared;
using SuperWebSocket.SubProtocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebSocketServer.Filters;
using WebSocketServer.Models;

namespace WebSocketServer.Commands
{
    [LogTimeCommandFilter(Order = 0)]
    public class RegisterAccount : JsonSubCommand<JiveClientSession, RegisterUser>
    {
        protected override void ExecuteJsonCommand(JiveClientSession session, RegisterUser user)
        {
            DatabaseQueryResult result = DB.DbManager.RegisterUser(user.Username, user.Password);
            if(result.Success)
            {
                session.AppServer.TrySendEmail(string.Format("Thanks for signing up with Jive Messenger!.\r\nUse this validation code to activate your account:\r\n{0}", result.Value), "Jive Messenger registration", user.Username);
            }
            SendJsonMessage(session, new DatabaseQueryResponse(result.Success, result.StatusText));
        }
    }
}
